package empox.pos.operator;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

public class SetOperatorAdapter extends BaseAdapter {
	Context con;
	OperatorInfo[] oi;
	boolean[] b;

	public SetOperatorAdapter(Context mContext) {
		con = mContext;
	}

	public void setValue(OperatorInfo[] mOperatorInfo, boolean[] bl) {
		oi = mOperatorInfo;
		b = bl;
	}

	public void setValue(boolean[] bl) {
		b = bl;
	}

	public int getCount() {
		if (oi != null)
			return oi.length;
		else
			return 0;
	}

	public Object getItem(int arg0) {
		return arg0;
	}

	public long getItemId(int arg0) {
		return arg0;
	}

	static class SH {
		CheckBox cb;
		TextView tv2;
		TextView tv3;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		SH sh = new SH();

		if (convertView == null) {
			convertView = new LinearLayout(con);
			((LinearLayout) convertView).setGravity(Gravity.CENTER);

			sh.cb = new CheckBox(con);
			sh.cb.setFocusable(false);
			sh.cb.setEnabled(false);
			sh.cb.setWidth(50);
			((LinearLayout) convertView).addView(sh.cb);

			sh.tv2 = new TextView(con);
			sh.tv2.setTextColor(0xff57290a);
			sh.tv2.setWidth(200);
			sh.tv2.setHeight(30);
			sh.tv2.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.tv2);

			sh.tv3 = new TextView(con);
			sh.tv3.setTextColor(0xff57290a);
			sh.tv3.setWidth(200);
			sh.tv3.setHeight(30);
			sh.tv3.setGravity(Gravity.CENTER);
			((LinearLayout) convertView).addView(sh.tv3);

			convertView.setTag(sh);
		} else {
			sh = (SH) convertView.getTag();
		}

		sh.cb.setChecked(b[position]);
		sh.tv2.setText(oi[position].power);
		sh.tv3.setText(oi[position].userName);

		return convertView;
	}

}
